
clear;
close all;
%cd C:\_bcoe\EDF_Data\;
%cd('C:\bcoe\crap')
c=clock;
day=[num2str(c(1)) '-' num2str(c(2)) '-' num2str(c(3)) ];
if day(7)=='-'
    day=[day(1:5), '0',day(6:end)];
end
if length(day)==9;
    day=[day(1:8), '0',day(9:end)];
end
warning off MATLAB:MKDIR:DirectoryExists
eval(['mkdir ' day]);
warning on MATLAB:MKDIR:DirectoryExists
eval(['cd ' day]);

c=define_colors(uint8(256));
c.BACKGROUND=c.M_GREY;


scnsize = get(0,'ScreenSize');
screenpixH=scnsize(3);
screenpixW=scnsize(4);
c_x=screenpixH/2;
c_y=screenpixW/2;
% for now....
dist2screen=60;%cm
screenwidth=40;%cm
    dphs = atan2(screenwidth/2,dist2screen)*180/pi;%degrees per half screen
    ppd = (screenpixW)/2/dphs; %pixels/degree

fix=round([c_x c_y c_x c_y]+([-1 -1	1 1]*ppd*.5));
stim=round(([-1 -1	1 1]*ppd*3));
loc_AngEcc=	[ 45 12; 135 12; 225 12; 315 12];    % ang & ecc positions. only change this line!!!
n_loc=length(loc_AngEcc);
loc_XY=[]; 
[loc_XY(:,1) loc_XY(:,2)]=polar2cart(loc_AngEcc(:,1),loc_AngEcc(:,2),1);   
[loc_XYm(:,1) loc_XYm(:,2)]=polar2cart(loc_AngEcc(:,1),loc_AngEcc(:,2)+.6,1);  % the +.6 is for the width of the targtes which may have to be changed 
pixloc_XY=[];
pixloc_XY(:,1)=(loc_XY(:,1)*ppd)+c_x;% set ang&ecc to x&y based on screen size
pixloc_XY(:,2)=(loc_XY(:,2)*ppd)+c_y;
for i=1:n_loc
	tgt_rect(i,:)=round([pixloc_XY(i,:) pixloc_XY(i,:)]+stim); % for use with mac's LeToRiBo rect shite
end

try
[w, wRect]=Screen('OpenWindow', 2);
SCREEN(w,'fillrect',c.BACKGROUND); 
setmouse(scnsize(3),scnsize(4)); % force mouse to edge 
[m_x m_y buttons]=getmouse;
buttons=0;
toggle=1;
while buttons(1)==0
   SCREEN(w,'filloval',c.BLACK,fix)  
    if toggle
        SCREEN(w,'filloval',round(c.RED  *(screenpixH/screenpixH)),tgt_rect(1,:))  
        SCREEN(w,'filloval',round(c.RED  *(screenpixH/screenpixH)),tgt_rect(2,:))  
        SCREEN(w,'filloval',round(c.RED  *(screenpixH/screenpixH)),tgt_rect(3,:))  
        SCREEN(w,'filloval',round(c.RED  *(screenpixH/screenpixH)),tgt_rect(4,:))  
    else
        SCREEN(w,'filloval',round(c.GREEN*(m_y/screenpixW)),tgt_rect(1,:))  
        SCREEN(w,'filloval',round(c.GREEN*(m_y/screenpixW)),tgt_rect(2,:))  
        SCREEN(w,'filloval',round(c.GREEN*(m_y/screenpixW)),tgt_rect(3,:))  
        SCREEN(w,'filloval',round(c.GREEN*(m_y/screenpixW)),tgt_rect(4,:))  
    end
    toggle=abs(toggle-1);
    SCREEN('flip',w);
    [m_x m_y buttons]=getmouse;  
end
SCREEN(w,'Close');
disp(' ');
disp(['set RED to ' num2str(round(screenpixH/screenpixH*1000)/10) '%']);
disp(['set GREEN to ' num2str(round(m_y/screenpixW*1000)/10) '%']);
figure(1);
vfill(1,2,double(c.RED)/256*(screenpixH/screenpixH));
vfill(0,1,double(c.GREEN)/256*(m_y/screenpixW));
catch badness
    badness.message
    badness.stack
    shit
end
